package com.jbm.framework.tools;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jbm.framework.metadata.exceptions.http.HttpConnectionException;
import com.jbm.framework.metadata.exceptions.http.HttpRequestException;
import com.jbm.framework.metadata.usage.bean.http.ResponseWrapper;

public interface IHttpClient {

	public static final String CHARSET = "utf-8";
	public static final String CONTENT_TYPE_JSON = "application/json";
	public static final String CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";
	public static final String MEDIATYPE_CHARSET = "; charset=" + CHARSET;

	public static final String RATE_LIMIT_QUOTA = "X-Rate-Limit-Limit";
	public static final String RATE_LIMIT_Remaining = "X-Rate-Limit-Remaining";
	public static final String RATE_LIMIT_Reset = "X-Rate-Limit-Reset";
	public static final String DEF_USER_AGENT = "Java-Client";

	public static final int RESPONSE_OK = 200;

	public enum RequestMethod {
		GET, POST, PUT, DELETE
	}

	public static final String IO_ERROR_MESSAGE = "Connection IO error. \n" + "Can not connect to Http Server. " + "Please ensure your internet connection is ok. \n"
		+ "If the problem persists, please let us know at support@jpush.cn.";

	public static final String CONNECT_TIMED_OUT_MESSAGE = "connect timed out. \n" + "Connect to Http Server timed out, and already retried some times. \n"
		+ "Please ensure your internet connection is ok. \n" + "If the problem persists, please let us know at support@jpush.cn.";

	public static final String READ_TIMED_OUT_MESSAGE = "Read timed out. \n" + "Read response from Http Server timed out. \n"
		+ "If this is a Push action, you may not want to retry. \n" + "It may be due to slowly response from Http Server, or unstable connection. \n"
		+ "If the problem persists, please let us know at support@jpush.cn.";

	public static Gson _gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

	// 设置连接超时时间
	public static final int DEFAULT_CONNECTION_TIMEOUT = (5 * 1000); // milliseconds

	// 设置读取超时时间
	public static final int DEFAULT_READ_TIMEOUT = (30 * 1000); // milliseconds

	public static final int DEFAULT_MAX_RETRY_TIMES = 3;

	// public void setUserAgent(String userAgent);

	public ResponseWrapper sendGet(String url) throws HttpConnectionException, HttpRequestException;

	public ResponseWrapper sendDelete(String url) throws HttpConnectionException, HttpRequestException;

	public ResponseWrapper sendPost(String url, String content) throws HttpConnectionException, HttpRequestException;

	public ResponseWrapper sendPut(String url, String content) throws HttpConnectionException, HttpRequestException;

	public ResponseWrapper sendFormPost(String url, String content) throws HttpConnectionException, HttpRequestException;

	public ResponseWrapper sendFormPut(String url, String content) throws HttpConnectionException, HttpRequestException;
}
